package com.a.plugin.writer;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.sax.StartElementListener;
import android.webkit.WebSettings.PluginState;

import com.a.html5nfc.writer.NFCWriterActivity;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.PluginResult.Status;

public class PluginWriter extends Plugin {

    @Override
    public PluginResult execute(String action, JSONArray args, String callbackId) {
        Intent intent = new Intent();
        intent.setClass(this.ctx, NFCWriterActivity.class);
        try {
            String input = null;
            for(int i = 0; i < args.length(); i++) {
                JSONObject obj = args.getJSONObject(i);
                if(obj == null) {
                    break;
                }
                input = obj.getString("input");
                if(input != null) {
                    break;
                }
            }
            intent.putExtra("input", input);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        this.ctx.startActivity(intent);
        return new PluginResult(Status.OK, "");
    }
}
